package com.yh.services.impl;

import com.yh.dao.BooksMapper;
import com.yh.entity.Books;
import com.yh.entity.Page;
import com.yh.services.IBooksService;
import lombok.Getter;
import lombok.Setter;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

@Service
public class BooksServiceImpl implements IBooksService {
    @Getter
    @Setter
    @Resource
    private BooksMapper booksMapper;

    @Override
    public Page getLikeAllByX(Map<String, Object> book) {
        Page page=new Page();
        //获得总条数
        page.setTotalNum(booksMapper.getLikeAllCount(book));
        //获取显示条数
        int pageSize=Integer.parseInt(String.valueOf(book.get("pageSize")));
        page.setPageSize(pageSize);
        //获取当前页
        int pageNum=Integer.parseInt(String.valueOf(book.get("pageNum")));
        page.setPageNum(pageNum);
        //获取总页数
        page.setTotalPage(page.getTotalNum()/pageSize+(page.getTotalNum()%pageSize==0?0:1));
        //根据条件获得结果列表
        booksMapper.getLikeAllByX(book);
        page.setResult(booksMapper.getLikeAllByX(book));

        return page;
    }

    @Override
    public void addBooks(Books books) {
        booksMapper.addBooks(books);
    }

    @Override
    public void delBooks(Books books) {
    booksMapper.delBooks(books);
    }

    @Override
    public Books getBooksById(Books books) {
        return booksMapper.getBooksById(books);
    }

    @Override
    public void updateBooks(Books books) {
        booksMapper.updateBooks(books);
    }

}
